﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using spring.salesman.Models;
using spring.salesman.data;

namespace spring.salesman.Controllers
{
    public class UserController : Controller
    {
        //
        // GET: /User/

        public ActionResult Index()
        {
            return View();
        }


        /// <summary>
        /// 请求/user/edit
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ActionResult Edit()
        {
            UserModel model = new UserModel();

            if (!String.IsNullOrEmpty(Request.QueryString["uid"])) {

                //查询，赋值UserModel
            }

            return View(model);
        }

        /// <summary>
        /// 提交数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Edit(UserModel model) {

            SalemanDBEntities dbEntities = new SalemanDBEntities();

           

            b_User user = new b_User();
            user.UserID = dbEntities.GetTablePK("b_User");
            user.Address = model.Address;
            user.Birthday = model.Birthday;
            user.City = model.City;
            user.CreateDt = DateTime.Now;
            user.CreateIP = Request.UserHostAddress;
            user.Email = model.Email;

            user.Name = model.Name;
            user.Province = model.Province;
            user.QQ = model.QQ;
            user.Remark = model.Remark;
            user.Sex = model.Sex;
            user.Telephone = model.Telephone;

            dbEntities.AddTob_User(user);
            dbEntities.SaveChanges();
            return View(model);
        }
    }
}
